home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Musique / Quod Libet / quodlibet-3.3.0-installer.exe / bin / quodlibet / mmkeys / __init__.pyc (.txt) next >
Python Compiled Bytecode  |  2014-12-31  |  3KB  |  110 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4. from _base import MMKeysAction, MMKeysImportError
  5.  
  6. def iter_backends():
  7.     
  8.     try:
  9.         GnomeBackend = GnomeBackend
  10.         MateBackend = MateBackend
  11.         import gnome
  12.     except MMKeysImportError:
  13.         pass
  14.  
  15.     yield GnomeBackend
  16.     yield MateBackend
  17.     
  18.     try:
  19.         KeybinderBackend = KeybinderBackend
  20.         import keybinder
  21.     except MMKeysImportError:
  22.         pass
  23.  
  24.     yield KeybinderBackend
  25.     
  26.     try:
  27.         PyHookBackend = PyHookBackend
  28.         import pyhook
  29.     except MMKeysImportError:
  30.         pass
  31.  
  32.     yield PyHookBackend
  33.     
  34.     try:
  35.         OSXBackend = OSXBackend
  36.         import osx
  37.     except MMKeysImportError:
  38.         pass
  39.  
  40.     yield OSXBackend
  41.  
  42.  
  43. def find_active_backend():
  44.     print_d('Trying to find a mmkeys backend')
  45.     for backend in iter_backends():
  46.         if backend.is_active():
  47.             print_d('Found %r' % backend.__name__)
  48.             return backend
  49.     
  50.  
  51.  
  52. class MMKeysHandler(object):
  53.     '''Manages multiple keybinding backends and translates the generated
  54.     events to actions on the player backend.
  55.     '''
  56.     
  57.     def __init__(self, window, player):
  58.         self._backend = None
  59.         self._window = window
  60.         self._player = player
  61.  
  62.     
  63.     def start(self):
  64.         kind = find_active_backend()
  65.         if not kind:
  66.             return None
  67.         self._backend = None('Quod Libet', self._callback)
  68.         self._backend.grab()
  69.         self._window.connect('notify::is-active', self._focus_event)
  70.  
  71.     
  72.     def quit(self):
  73.         if self._backend:
  74.             self._backend.cancel()
  75.             self._backend = None
  76.             self._window = None
  77.             self._player = None
  78.  
  79.     
  80.     def _focus_event(self, window, param):
  81.         if window.get_property(param.name) and self._backend:
  82.             self._backend.grab()
  83.  
  84.     
  85.     def _callback(self, action):
  86.         print_d('Event %r from %r' % (action, type(self._backend).__name__))
  87.         player = self._player
  88.         if action == MMKeysAction.PREV:
  89.             player.previous()
  90.         elif action == MMKeysAction.NEXT:
  91.             player.next()
  92.         elif action == MMKeysAction.STOP:
  93.             player.stop()
  94.         elif action == MMKeysAction.PLAY:
  95.             if player.song is None:
  96.                 player.reset()
  97.             else:
  98.                 player.paused = False
  99.         elif action == MMKeysAction.PLAYPAUSE:
  100.             if player.song is None:
  101.                 player.reset()
  102.             else:
  103.                 player.paused ^= True
  104.         elif action == MMKeysAction.PAUSE:
  105.             player.paused = True
  106.         elif not 0:
  107.             raise AssertionError('unhandled event')
  108.  
  109.  
  110.